import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.function.Consumer;

public class ListSet<Item> extends MySet<Item> {

        class Node{
            Node next;
            Item data;
        }

        Node head;

        public ListSet(){
            head=null;
        }

        final class ListSetIterator implements Iterator<Item> {
            Node now = head;

            public ListSetIterator(){
                now=head;
            }

            @Override
            public boolean hasNext() {
                return now!=null;
            }

            @Override
            public Item next() {
                Item nowItem = now.data;
                now=now.next;
                return  nowItem;
            }

        }

        @Override
        public Iterator iterator() {
            return new ListSetIterator();
        }


        @Override
        public void addElement(Item item) {
            if(this.contains(item)){
                return;
            }
            Node n = new Node();
            n.next=head;
            n.data=item;
            head=n;
            size++;
        }

    @Override
    public boolean contains(Object o) {
        Node now=head;
        while(now!=null){
            if(now.data.equals(o)){
                return true;
            }
            now=now.next;
        }
        return false;
    }

}
